<div id="page-content">
	<div class="col-lg-12">
		<div class="panel">
			<div class="panel-heading">
				<h3 class="panel-title" style="text-align: right;">
					添加
				</h3>
			</div>
			<form id="editForm" class="panel-body form-horizontal form-padding">
				<input type="hidden"  name="#(formModelName).id" class="form-control" value="#(o?o.id:'')">
				<div class="form-group">
					<label class="col-md-1 control-label">单位</label>
					<div class="col-md-5">
						<input type="text"  name="#(formModelName).org_name" class="form-control"  value="#(o?o.org_name:'')" #if(view=='detail') readonly #end>
					</div>
					<label class="col-md-1 control-label">毛重</label>
					<div class="col-md-5">
						<input type="text"  name="#(formModelName).weight1" class="form-control"  value="#(o?o.weight1:'')" #if(view=='detail') readonly #end>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-1 control-label">品名</label>
					<div class="col-md-5">
						<input type="text"  name="#(formModelName).pin_name" class="form-control"  value="#(o?o.pin_name:'')" #if(view=='detail') readonly #end>
					</div>
					<label class="col-md-1 control-label">皮重</label>
					<div class="col-md-5">
						<input type="text"  name="#(formModelName).weight2" class="form-control"  value="#(o?o.weight2:'')" #if(view=='detail') readonly #end>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-1 control-label">车号</label>
					<div class="col-md-5">
						<input type="text"  name="#(formModelName).car_num" class="form-control"  value="#(o?o.car_num:'')" #if(view=='detail') readonly #end>
					</div>
					<label class="col-md-1 control-label">净重</label>
					<div class="col-md-5">
						<input type="text"  name="#(formModelName).weight3" class="form-control"  value="#(o?o.weight3:'')" #if(view=='detail') readonly #end onchange="toBig(this)">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-1 control-label">客户</label>
					<div class="col-md-5">
						<input type="text"  name="#(formModelName).customer" class="form-control"  value="#(o?o.customer:'')" #if(view=='detail') readonly #end>
					</div>
					<label class="col-md-1 control-label">大写</label>
					<div class="col-md-5">
						<input id="bigWeight" type="text"  name="#(formModelName).big_weight" class="form-control"  value="#(o?o.big_weight:'')" #if(view=='detail') readonly #end>
					</div>
				</div>
				#if(view=='detail')

				#else
				<div class="panel-footer">
					<div class="row">
						<div class="col-sm-8 col-sm-offset-3">
							<button class="btn btn-primary" type="submit" #if(view=='detail') disabled #end>导出</button>
						</div>
					</div>
				</div>
				#end
			</form>
		</div>
	</div>
</div>
<script>
	function save(){
		var data = common_ajax.ajaxFunc("/admin/sys/tool/weight/save", $('#editForm').serialize(), "json", null);
		if(data.success){
			location.href = ctx+'/admin/sys/tool/weight/export?id='+data.data.id;//跳转到列表页
		}else{
			pointLion.alertMsg(data.message , "danger" , "small" , function(){
				$(".btn").removeAttr("disabled");
			},data);
		}
	}
	function toBig(o){
		var value = $(o).val();
		var b = Arabia_To_SimplifiedChinese(value);
		$("#bigWeight").val(b);
	}
	$(document).ready(function() {
		$('#editForm').bootstrapValidator({
			fields: {
			}
		}).on("success.form.bv", function (e) {
			save();
			return false;//阻止表单跳转
		});
	});


	//阿拉伯数字转换为简写汉字
	function Arabia_To_SimplifiedChinese(Num) {
		for (i = Num.length - 1; i >= 0; i--) {
			Num = Num.replace(",", "")//替换Num中的“,”
			Num = Num.replace(" ", "")//替换Num中的空格
		}
		if (isNaN(Num)) { //验证输入的字符是否为数字
			//alert("请检查小写金额是否正确");
			return;
		}
		//字符处理完毕后开始转换，采用前后两部分分别转换
		part = String(Num).split(".");
		newchar = "";
		//小数点前进行转化
		for (i = part[0].length - 1; i >= 0; i--) {
			if (part[0].length > 10) {
				//alert("位数过大，无法计算");
				return "";
			}//若数量超过拾亿单位，提示
			tmpnewchar = ""
			perchar = part[0].charAt(i);
			switch (perchar) {
				case "0":  tmpnewchar = "零" + tmpnewchar;break;
				case "1": tmpnewchar = "壹" + tmpnewchar; break;
				case "2": tmpnewchar = "贰" + tmpnewchar; break;
				case "3": tmpnewchar = "叁" + tmpnewchar; break;
				case "4": tmpnewchar = "肆" + tmpnewchar; break;
				case "5": tmpnewchar = "伍" + tmpnewchar; break;
				case "6": tmpnewchar = "陆" + tmpnewchar; break;
				case "7": tmpnewchar = "柒" + tmpnewchar; break;
				case "8": tmpnewchar = "捌" + tmpnewchar; break;
				case "9": tmpnewchar = "玖" + tmpnewchar; break;
			}
			switch (part[0].length - i - 1) {
				case 0: tmpnewchar = tmpnewchar; break;
				case 1: if (perchar != 0) tmpnewchar = tmpnewchar + "拾"; break;
				case 2: if (perchar != 0) tmpnewchar = tmpnewchar + "佰"; break;
				case 3: if (perchar != 0) tmpnewchar = tmpnewchar + "仟"; break;
				case 4: tmpnewchar = tmpnewchar + "万"; break;
				case 5: if (perchar != 0) tmpnewchar = tmpnewchar + "拾"; break;
				case 6: if (perchar != 0) tmpnewchar = tmpnewchar + "佰"; break;
				case 7: if (perchar != 0) tmpnewchar = tmpnewchar + "仟"; break;
				case 8: tmpnewchar = tmpnewchar + "亿"; break;
				case 9: tmpnewchar = tmpnewchar + "拾"; break;
			}
			newchar = tmpnewchar + newchar;
		}
		//替换所有无用汉字，直到没有此类无用的数字为止
		while (newchar.search("零零") != -1 || newchar.search("零亿") != -1 || newchar.search("亿万") != -1 || newchar.search("零万") != -1) {
			newchar = newchar.replace("零亿", "亿");
			newchar = newchar.replace("亿万", "亿");
			newchar = newchar.replace("零万", "万");
			newchar = newchar.replace("零零", "零");
		}
		//替换以“一十”开头的，为“十”
		if (newchar.indexOf("一十") == 0) {
			newchar = newchar.substr(1);
		}
		//替换以“零”结尾的，为“”
		if (newchar.lastIndexOf("零") == newchar.length - 1) {
			newchar = newchar.substr(0, newchar.length - 1);
		}
		return newchar;
	}
</script>